#include <iostream>
#include <string>
#include "textContent.h"

using std::string;
using std::cout;
using std::map;

textContent::textContent(void)
{
	posCount = 0;
	wordCount = 0;
}

void textContent::addWord(string word)
{
	map<string, int>::iterator it;
	it = wordMap.find(word);	
	if(it != wordMap.end())
	{
		codeListMap[posCount] = int(it->second);
		posCount++;
	}
	else
	{
		wordMap[word] = wordCount;
		wordListMap[wordCount] = word;
		codeListMap[posCount] = wordCount;
		posCount++;
		wordCount++;
	}
}

void textContent::addListWord(string word)
{
	wordListMap[wordCount]=word;
	wordCount++;
}

void textContent::addCode(int wordIndex)
{
	codeListMap[posCount] = wordIndex;
	posCount++;
}

string textContent::getWordAtPos(int pos)
{
	return wordListMap[codeListMap[pos]];
}

int textContent::getWordCound()
{
	return wordCount;
}

int textContent::getPosCound()
{
	return posCount;
}

int textContent::getPos(int numPos)
{
	return codeListMap[numPos];
}

string textContent::getListWord(int Listnum)
{
	return wordListMap[Listnum];
}

void textContent::setBin(bool isThisBin)
{
	isBin = isThisBin;
}

bool textContent::getBin()
{
	return isBin;
}

void textContent::printud()
{
	map<string, int>::iterator i;
	map<string, int>::iterator iend = wordMap.end();
	//for(i=wordMap.begin();i!=iend;++i)
	//{
	//	cout << i->first << " " << i->second << std::endl;
	//}

	for(int h=0;h<wordCount;++h)
	{
		cout << wordListMap[h] << " "<< h << std::endl;
	}



	for(int h=0;h<posCount;++h)
	{
		cout << codeListMap[h] <<  " ";
	}

	cout << std::endl;

}

textContent::~textContent(void)
{
}
